-
Write something in the document below!
- There is at least one public document in every node in the Agora. Whatever you write in it will be integrated and made available for the next visitor to read and edit.
- Write to the Agora from social media.
-
Sign up as a full Agora user.
- As a full user you will be able to contribute your personal notes and resources directly to this knowledge commons. Some setup required :)
Python Loops - For Loops
Go to the [[Python Week 3 Main Page]] or the [[Python - Main Page]] Also see the [[Programming Main Page]] or the [[Main AI Page]]
Also see [[Python Loops - While Loops]]
For code examples see the [[Week3 Python For and While Loops Lab]]
For Loops
A loop that executes for each element in an iterable.
Syntax
for i in range(4)
nephilim[i] = "Redacted"
Keep in mind, for iterable lists and tuples, you do not need to use the range function if you are iterating through the whole list. An ad-hoc variable representing the elements of the list will do the job instead.
for member in nephilim:
member = "redacted"
The Range() Function
The range()
function outputs an ordered sequence as a list, i
, with the same number of elements as the input.
len(range(3))
--> 3 --> [0, 1, 2]
If the range()
function has two arguments, where the first argument is smaller than the second argument, than the sequence starts at the first argument and iterates up to but not including the second.
range(15,20)
--> [15, 16, 17, 18, 19]
The Enumerate() Function
Provides a counter for a list when looping through it with a for
loop.
for i,member in enumerate(nephilim)
nephilim.name = "Redacted"
print("Nephilim ", i + 1, " has had their name redacted.")
- public document at doc.anagora.org/python-loops-for-loops|for-loops
- video call at meet.jit.si/python-loops-for-loops|for-loops
(none)
(none)
(none)